home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / hobbspr2 / test.cpp < prev    next >
C/C++ Source or Header  |  1992-09-21  |  5KB  |  166 lines

  1. #include <stdlib.h>
  2. #include <conio.h>
  3. #include <dos.h>
  4. #include "hobbes.h"
  5. #include "sprite.h"
  6. #include "tile.h"
  7.  
  8. void scroll(void);
  9.  
  10. #define TILE_W 16
  11. #define TILE_H 16
  12.  
  13. TTileMap     testmap(TILE_W,TILE_H,0,0);
  14.  
  15.  
  16. #define MAP_W 200
  17. #define MAP_H 200
  18.  
  19. #define MAP1_W 50
  20. char map1[MAP1_W][MAP_H] = {                                        //25==*
  21. { 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 },
  22. { 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9 },
  23. { 9, 1, 0, 1, 0, 2, 2, 2, 0, 3, 0, 0, 0, 4, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 0, 0, 0, 5, 5, 0, 0, 6, 0, 0, 6, 0, 1, 1, 1, 0, 2, 2, 2, 2, 2, 9 },
  24. { 9, 1, 0, 1, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 5, 0, 0, 0, 0, 0, 0, 4, 0, 0, 4, 0, 5, 0, 0, 5, 0, 6, 0, 0, 6, 0, 1, 0, 1, 0, 0, 0, 2, 0, 0, 9 },
  25. { 9, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9 },
  32. { 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 },
  33. };
  34.  
  35.  
  36. #define VIRT_W 400
  37. #define VIRT_H 240
  38.  
  39. main() {
  40.  
  41.     Set320x240Mode();
  42.     SetVirtualPort(VIRT_W,VIRT_H);
  43.     SetClipPort(0,0,VIRT_W,VIRT_H);
  44. //     SetSplit(220);
  45. //    FlipPage();
  46. //    testmap.SetMapPort(0,0,VIRT_W,VIRT_H);
  47.  
  48.  
  49.     for (int i=0; i<256; i++)
  50.         testmap.NewTile(i);
  51.  
  52.     for (i=0; i<MAP_W; i++)
  53.         for (int j=0; j<MAP_H; j++)
  54.             testmap.SetTile(i,j, 0); //map1[j][i]);
  55.  
  56.     char *blah[1] = {"kite2.bit"};
  57.     TSprite     sprkite(blah,1);
  58.     TBitmap        kite("kite.bit");
  59.     TBitmap        tree("tree.bit");
  60.     TBitmap        ground("ground.bit");
  61.     Tile_Handle Hkite     = testmap.NewTile(&kite);
  62.     Tile_Handle Htree     = testmap.NewTile(&tree);
  63.     Tile_Handle Hground = testmap.NewTile(&ground);
  64.  
  65.  
  66.     for(i=0; i<200; i++)
  67.         testmap.SetTile(i,8,Hground);
  68. //    for(i=0; i<20; i++)
  69. //        testmap.SetTile(random(200),8,Htree);
  70.     testmap.SetTile(0,8,Htree);
  71.     testmap.SetTile(1,8,Htree);
  72.     testmap.SetTile(2,8,Htree);
  73.     testmap.SetTile(6,8,Htree);
  74.     testmap.SetTile(7,8,Htree);
  75.     testmap.SetTile(8,8,Htree);
  76.     testmap.SetTile(12,8,Htree);
  77.     testmap.SetTile(13,8,Htree);
  78.     testmap.SetTile(14,8,Htree);
  79.     testmap.SetTile(18,8,Htree);
  80.     testmap.SetTile(19,8,Htree);
  81.     testmap.SetTile(20,8,Htree);
  82.     testmap.SetTile(24,8,Htree);
  83.     testmap.SetTile(25,8,Htree);
  84.     testmap.SetTile(26,8,Htree);
  85.  
  86.     for(i=0; i<30; i++)
  87.         testmap.SetTile(random(200),random(8),Hkite);
  88.  
  89.  
  90.     testmap.SetMapVirtualPort(0,0,VIRT_W,VIRT_H);
  91.     testmap.DisplayStart.SetXY(0,0);
  92.     testmap.MapLoc.SetXY(10,10);
  93.     testmap.DrawWholeMap();
  94.  
  95.     SetMousePort(0,0,10000,500);
  96.     MouseInit(10,10,WHITE);
  97.     MouseSetCursorShape(UserDef1);
  98.     sprkite.SetXY(100,100);
  99.     int curmx=MouseX, curmy=MouseY;
  100.  
  101.     while (1) {
  102.         if (MouseRightPressed())
  103.             break;
  104.         sprkite.SetXY(MouseX,MouseY+10);
  105.         sprkite.Draw();
  106.         scroll();
  107.         testmap.Dirty(&sprkite);
  108.         }
  109.  
  110.     MouseUnInit();
  111.     RestoreTextMode();
  112.     return 0;
  113. }
  114.  
  115.  
  116. unsigned char readkb(void);
  117. unsigned char readkb()
  118. {
  119.     _AH = 0x08;
  120.     geninterrupt(0x21);    // DOS keyboard interrupt
  121.     return _AL;
  122. }
  123.  
  124.  
  125. void scroll(void)
  126. {
  127.     static int x=0, y = 0, maxx, maxy, dx = 0, dy = 0;
  128.     unsigned char c;
  129.     int curmx=MouseX,
  130.         curmy=MouseY;
  131. //    maxx = (Virtual_Width_Pix - Physical_Width_Pix) /4;
  132. //    maxy = (Virtual_Height_Pix - Physical_Height_Pix);
  133. //    maxx = MAP_W * 20;
  134. //    maxy = MAP_H * 20;
  135.     maxx = MAP_W * TILE_W;
  136.     maxy = MAP_H * TILE_H;
  137.     if(kbhit()) {
  138.         c = readkb();
  139.         if(c == 27) exit(0);
  140.         if(c == 0) {
  141.             c = readkb();
  142.             if(c == 72) dy = -1;
  143.             else if(c == 80) dy = 1;
  144.             else if(c == 75) dx = -1;
  145.             else if(c == 77) dx = 1;
  146.         }
  147.         else dx = dy = 0;
  148.     }
  149.     if((x < 1) && (dx == -1)) dx = 0;
  150.     if((y < 1) && (dy == -1)) dy = 0;
  151.     x += dx;
  152.     y += dy;
  153.     if(x > maxx) {
  154.         x = maxx;
  155.         dx = 0;
  156.     }
  157.     if(y > maxy) {
  158.         y = maxy;
  159.         dy = 0;
  160.     }
  161.     if (MouseX-curmx)
  162.         testmap.Move(MouseX-curmx);
  163.     testmap.Move(dx);
  164. //    SetDisplay(x,y);
  165. }
  166.